/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package smartgrid;

import org.orm.PersistentException;
public class MesAgregadoProcessor {
	private int ID;
	
	private double gastoAVG;
	
	private double gastoSUM;
	
	private double precoAVG;
	
	private double precoSUM;
	
	private String unidade;
	
	private java.util.Date data;
	
	private String action="";
	
	public void setID(int value) {
		this.ID = value;
	}
	
	public int getID() {
		return ID;
	}
	
	public void setGastoAVG(double value) {
		this.gastoAVG = value;
	}
	
	public double getGastoAVG() {
		return gastoAVG;
	}
	
	public void setGastoSUM(double value) {
		this.gastoSUM = value;
	}
	
	public double getGastoSUM() {
		return gastoSUM;
	}
	
	public void setPrecoAVG(double value) {
		this.precoAVG = value;
	}
	
	public double getPrecoAVG() {
		return precoAVG;
	}
	
	public void setPrecoSUM(double value) {
		this.precoSUM = value;
	}
	
	public double getPrecoSUM() {
		return precoSUM;
	}
	
	public void setUnidade(String value) {
		this.unidade = value;
	}
	
	public String getUnidade() {
		return unidade == null ? "" : unidade;
	}
	
	public void setData(java.util.Date value) {
		this.data = value;
	}
	
	public java.util.Date getData() {
		return data;
	}
	
	public String getAction() {
		return action;
	}
	
	public void setAction(String action) {
		this.action = action;
	}
	
	private int contract_contractID;
	
	public void setContract_contractID(int value) {
		this.contract_contractID = value;
	}
	
	public int getContract_contractID() {
		return contract_contractID;
	}
	
	public String process() {
		String result = "Unexcepted result";
		if (action.equals("search")) {
			smartgrid.MesAgregado _mesAgregado = smartgrid.MesAgregado.loadMesAgregadoByORMID(getID());
			if (_mesAgregado!= null) {
				copyFromBean(_mesAgregado);
				result = "Search success";
			}
			else {
				result = "Search failed";
			}
		}
		else if(action.equals("insert"))  {
			try {
				smartgrid.MesAgregado _mesAgregado = smartgrid.MesAgregado.createMesAgregado();
				copyToBean(_mesAgregado);
				if (_mesAgregado.save()) {
					result = "Insert success";
				}
				else {
					result = "Insert failed";
				}
			}
			catch (Exception e) {
				result = "Insert error: " + e.toString();
			}
		}
		else if (action.equals("update")) {
			smartgrid.MesAgregado _mesAgregado= smartgrid.MesAgregado.loadMesAgregadoByORMID(getID());
			if (_mesAgregado != null) {
				copyToBean(_mesAgregado);
				if (_mesAgregado.save()) {
					result = "Update success";
				}
				 else {
					result = "Update failed";
				}
			}
			 else  {
				result = "Update failed";
			}
			
		}
		else if (action.equals("delete")) {
			smartgrid.MesAgregado _mesAgregado = smartgrid.MesAgregado.loadMesAgregadoByORMID(getID());
			if (_mesAgregado != null && _mesAgregado.deleteAndDissociate()) {
				result = "Delete success";
			}
			else {
				result = "Delete failed";
			}
		}
		else if (action.equals("")) {
			result = "";
		}
		action = "";
		return result;
	}
	
	private void copyFromBean(smartgrid.MesAgregado _mesAgregado) {
		setGastoAVG(_mesAgregado.getGastoAVG());
		setGastoSUM(_mesAgregado.getGastoSUM());
		setPrecoAVG(_mesAgregado.getPrecoAVG());
		setPrecoSUM(_mesAgregado.getPrecoSUM());
		setUnidade(_mesAgregado.getUnidade());
		setData(_mesAgregado.getData());
		setID(_mesAgregado.getORMID());
		
		{
			smartgrid.Contract _contract = _mesAgregado.getContract();
			if (_contract != null) {
				setContract_contractID(_contract.getORMID());
			}
		}
		
	}
	
	private void copyToBean(smartgrid.MesAgregado _mesAgregado) {
		_mesAgregado.setGastoAVG(getGastoAVG());
		_mesAgregado.setGastoSUM(getGastoSUM());
		_mesAgregado.setPrecoAVG(getPrecoAVG());
		_mesAgregado.setPrecoSUM(getPrecoSUM());
		_mesAgregado.setUnidade(getUnidade());
		_mesAgregado.setData(getData());
		smartgrid.Contract _contract = smartgrid.Contract.loadContractByORMID(getContract_contractID());
		_mesAgregado.setContract(_contract);
	}
	
}

